/*--------------------------数据定义------------------------------*/
const socket = io(WS_SERVER);
// 场景参数
let renderer, camera, scene, control,labelRenderer,light
const cameraPos=[2.5, 2.5, 2.5] // 相机初始位置


// 人物相关
const player = new THREE.Group(); // 玩家
const playerPos=[0,0,0] //人物初始位置
let target=new THREE.Vector3(); // 移动目标
let distance // 移动距离
let targetNorm // 移动方向
let speed=0.08 // 移动速度
let walking=false // 人物状态 【0：静止 1：移动】
let mode // 加载后的人物模型
let playerOnFloor=false // 玩家是否在地面

//动画
const mixers = []; // 动画混合数组
let action; // 玩家所有动作
const animations=[] // 其他角色动画集合{id:1,action:{}}
const clock = new THREE.Clock(); // 时间流

// 碰撞
const GRAVITY = 30; // 重力加速度
const STEPS_PER_FRAME=5 // 每帧检测次数
const worldOctree = new Octree(); // 八叉树空间实例
const playerVelocity = new THREE.Vector3(); // 玩家空间速度
// 玩家碰撞范围（几何胶囊作为碰撞实体）
const playerCollider = new Capsule( new THREE.Vector3( 0, 0.35, 0 ), new THREE.Vector3( 0, 1.4, 0 ), 0.35 ); 

// 显示碰撞范围
const sphereGeometry = new THREE.IcosahedronGeometry( playerCollider.radius, 5 );
const sphereMaterial = new THREE.MeshLambertMaterial( { color: 0xbbbb44 ,transparent:true,opacity:0.5} );
const cylinderGeometry=new THREE.CylinderGeometry(playerCollider.radius,playerCollider.radius,1.04,50)
const sphere1 = new THREE.Mesh( sphereGeometry, sphereMaterial );
const sphere2 = new THREE.Mesh( sphereGeometry, sphereMaterial );
const body=new THREE.Mesh(cylinderGeometry,sphereMaterial)


// 运行设置
const showCollider=false //显示碰撞模型
const showHelper=false // 显示辅助线

const keyStates = {}; // 键盘按键状态

const isMobile=(function(){
    let userAgentInfo = navigator.userAgent;
    let mobileAgents = [
      "Android",
      "iPhone",
      "SymbianOS",
      "Windows Phone",
      "iPad",
      "iPod",
    ];
    let mobile_flag = false;
  
    //根据userAgent判断是否是手机
    for (let v = 0; v < mobileAgents.length; v++) {
      if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
        mobile_flag = true;
        break;
      }
    }
    let screen_width = window.screen.width;
    let screen_height = window.screen.height;
    //根据屏幕分辨率判断是否是手机
    if (screen_width < 500 && screen_height < 800) {
      mobile_flag = true;
    }
    return mobile_flag;
}())
